/**
 * Created by coder on 2017/2/23.
 */
import TokenManager from './WtTokenManager'
import WtLogger from './WtLogger'
import {logout} from './WtLogout'
import {HostUrl} from "../config/config";




export default function WtHostPost(url,data,needToken = false){
	const token = needToken ? TokenManager.getToken() : null;
	if(needToken && !token){
		//没有找到token
		return new Promise((resolve,reject) => {reject({code:1401,msg:'not found token'})});
	}

	return fetch(HostUrl+url,{
		//credentials: 'include',
		method:'POST',
		headers:{
			'Content-Type':'application/json',
		},
		body:JSON.stringify(data)
	}).then((response) => {
		return response.json().then((json) => {
			return {json,header:response.headers};
		})
	}).then(({json,header}) => {
		return DefaultCheckPost(json,header,url,data,needToken,token);
	});
}

function DefaultCheckPost(json,header,url,data,needToken,token){
	return {json,header};
}
